package com.cd2cd.util;

public class ThreadLocalUtil {

    private static InheritableThreadLocal<HolderObj> idLocal;

    static {
        idLocal = new InheritableThreadLocal<>();
    }

    private static HolderObj getHolderObj() {
        HolderObj holder = idLocal.get();
        if(holder == null) {
            holder = new HolderObj();
            idLocal.set(new HolderObj());
        }
        return holder;
    }

    public static String getProjectBasePkg() {
        return getHolderObj().getProjectBasePkg();
    }

    public static void setProjectBasePkg(String projectBasePkg) {
        HolderObj ho = getHolderObj();
        ho.setProjectBasePkg(projectBasePkg);
        idLocal.set(ho);
    }

    public static class HolderObj {
        private String projectBasePkg; // 项目 base package :groupId + artifactIdName

        public String getProjectBasePkg() {
            return projectBasePkg;
        }

        public void setProjectBasePkg(String projectBasePkg) {
            this.projectBasePkg = projectBasePkg;
        }
    }
}
